package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSON;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.vo.album.AlbumCategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@Slf4j
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {

	private final BaseCategoryService baseCategoryService;
	@Autowired
	public BaseCategoryApiController(BaseCategoryService baseCategoryService) {
		this.baseCategoryService = baseCategoryService;
	}

	/**
	 * @description: 查询所有专辑分类数据
	 * @author Petrichor
	 * @date 2023/12/20 9:57
	 * @return AlbumCategoryVo 专辑分类数据 [专辑分类名称,专辑分类Id,专辑子分类集合]
	 **/
	@Operation(summary = "查询所有分类数据")
	@GetMapping("/getBaseCategoryList")
	public Result<List<AlbumCategoryVo>> getBaseCategoryList(){
		List<AlbumCategoryVo> albumCategoryVoList = baseCategoryService.getBaseCategoryList();
		return Result.ok(albumCategoryVoList);
	}
	/**
	 * @description: 查询专辑属性:根据分类Id查询专辑属性
	 * @author Petrichor
	 * @date 2023/12/21 18:33
	 * @param id 一级分类id
	 * @return 专辑属性
	 **/
	@GetMapping("/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttribute(@PathVariable(value = "category1Id") Long id){
		List<BaseAttribute> baseAttributeList = baseCategoryService.findAttribute(id);
		return Result.ok(baseAttributeList);
	}
	/**
	 * @description: 根据三级分类id查询分类数据
	 * @author Petrichor
	 * @date 2023/12/26 20:46
	 * @param c3Id Category3Id 专辑三级分类id
	 * @return BaseCategoryView 分类视图 一二三级分类的id和名称
	 **/
	@GetMapping(value = "/findCategoryByC3Id/{c3Id}")
	public Result<BaseCategoryView> findCategoryByC3Id(@PathVariable(value = "c3Id") Long c3Id) {
		BaseCategoryView baseCategoryView = baseCategoryService.findCategoryByC3Id(c3Id) ;
		return Result.build(baseCategoryView , ResultCodeEnum.SUCCESS) ;
	}
	/**
	 * @description: 根据一级分类id获取全部分类信息
	 * @author Petrichor
	 * @date 2023/12/27 22:31
	 * @param category1Id 一级分类id
	 * @return AlbumCategoryVo 专辑分类数据
	**/
	@Operation(summary = "根据一级分类id获取全部分类信息")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result<AlbumCategoryVo> getBaseCategoryList(@PathVariable(value = "category1Id") Long category1Id){
		AlbumCategoryVo albumCategoryVo = baseCategoryService.getAllCategoryList(category1Id);
		log.info("根据一级分类id获取全部分类信息:{}", JSON.toJSONString(albumCategoryVo));
		return Result.ok(albumCategoryVo);
	}
	/**
	 * @description: 根据一级分类id查询置顶三级分类
	 * @author Petrichor
	 * @date 2023/12/27 22:39
	 * @param category1Id 一级分类id
	 * @return 三级分类集合
	**/
	@Operation(summary = "根据一级分类id查询置顶三级分类")
	@GetMapping("findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id) {
		//	获取三级分类列表
		List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3ByCategory1Id(category1Id);
		//	返回数据
		return Result.ok(baseCategory3List);
	}
}

